package com.ivi.car.module.carstate.model;

import android.arch.lifecycle.Lifecycle;

import com.ivi.car.base.BaseModel;
import com.ivi.car.bean.carstate.FaultDetial;
import com.ivi.car.bean.carstate.PressureDetial;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.wm.machine.baselibrary.utils.StringUtils;

import java.util.ArrayList;

/**
 * Copyright
 * author chengxp
 * date 2018/3/8
 * describe 故障提醒的model
 * history
 */

public class FaultModel extends BaseModel {
    private static final String[] TEXTS = new String[]{"", "复位", "检测", "知道了"};

    public FaultModel(LifecycleProvider<Lifecycle.Event> provider) {
        super(provider);
    }

    /**
     * 获取胎压详情
     *
     * @return PressureDetial
     */
    public PressureDetial getPressureDetial() {
        PressureDetial detial = new PressureDetial(getRandomPressure(), getRandomTemperature(), getRandomPressure(),
                getRandomTemperature(), getRandomPressure(), getRandomTemperature(), getRandomPressure(), getRandomTemperature());
        return detial;
    }

    /**
     * 获取故障列表
     *
     * @return list
     */
    public ArrayList<FaultDetial> getFaultList() {
        ArrayList<FaultDetial> list = new ArrayList();
        for (int i = 0; i < 6; i++) {
            list.add(getFaultDetial());
        }
        return list;
    }

    private String getRandomPressure() {
        int num = (int) (300 + Math.random() * 15);
        return String.valueOf(num);
    }

    private String getRandomTemperature() {
        int num = (int) (20 + Math.random() * 10);
        return String.valueOf(num);
    }

    private FaultDetial getFaultDetial() {
        String one = "故障："+StringUtils.generateString(4);
        int type = (int) (0 + Math.random() * 3);
        String text = TEXTS[type];
        return new FaultDetial(one, type, text);
    }
}
